﻿using DevExpress.LookAndFeel;
using DevExpress.Skins;
using Pharmacy.Data;
using Pharmacy.Entities;

namespace Pharmacy.Windows.Forms.Main
{
    public partial class FormStock : DevExpress.XtraEditors.XtraForm
    {
        public FormStock()
        {
            InitializeComponent();
            int count;
            VList<StockWarning> list = DataRepository.StockWarningProvider.GetAll();
            gridControl2.DataSource = list;
        }

        //private void grv_StockWarning_RowStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowStyleEventArgs e)
        //{
        //    //if (e.RowHandle % 5 == 0)
        //    //{
        //    //    e.HighPriority = true;
        //    //    e.Appearance.BackColor = CommonColors.GetWarningColor(UserLookAndFeel.Default.ActiveLookAndFeel);
        //    //}
        //}

        private void grv_StockWarning_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.RowHandle > 0)
                if (e.Column == cWillExpiredIn)
                {
                    int warningLevel = (int)grv_StockWarning.GetRowCellValue(e.RowHandle, cExpiredDateWarning);
                    switch (warningLevel)
                    {
                        case 3:
                            e.Appearance.BackColor = CommonColors.GetCriticalColor(UserLookAndFeel.Default.ActiveLookAndFeel);
                            break;
                        case 2:
                            e.Appearance.BackColor = CommonColors.GetWarningColor(UserLookAndFeel.Default.ActiveLookAndFeel);
                            break;
                        case 1:
                            e.Appearance.BackColor =
                                CommonColors.GetInformationColor(UserLookAndFeel.Default.ActiveLookAndFeel);
                            break;
                    }
                }
                else if (e.Column == cInStock)
                {
                    int warningLevel = (int)grv_StockWarning.GetRowCellValue(e.RowHandle, cInStockWarning);
                    switch (warningLevel)
                    {
                        case 2:
                            e.Appearance.BackColor = CommonColors.GetCriticalColor(UserLookAndFeel.Default.ActiveLookAndFeel);
                            break;
                        case 1:
                            e.Appearance.BackColor = CommonColors.GetWarningColor(UserLookAndFeel.Default.ActiveLookAndFeel);
                            break;
                    }
                }
        }
    }
}